<template>
  <view>
    <view class="contract-number">合同编号：{{contractId}}</view>
    <view class="title">项目</view>
    <view class="contract-info-box">
      <view class="in-text">
        <view class="itext-word">
          项目
        </view><!-- contractWorkAddress -->
        <!-- "请选择工作地点" -->
        <view class="intext-in">
          <picker mode="selector" :range="workeAdderss" @change="setworkeAdderss($event)">
            <view style="color: #808080;">{{contractProjectName}}</view>
          </picker>
        </view>
      </view>


    </view>
    <view class="title">用人单位信息</view>
    <view class="contract-info-box">
      <view class="in-text">
        <view class="itext-word">
          用人单位名称
        </view>
        <view class="intext-in">
          <picker mode="selector" :range="subcontractingName" @change="setsubcontracting($event)">
            <view style="color: #808080;">{{unitName}}</view>
          </picker>
        </view>
      </view>
    </view>
    <view class="title">劳动者信息</view>
    <view class="contract-info-box">
      <view class="in-text">
        <view class="itext-word">
          劳动者姓名
        </view>
        <view class="intext-in">
          <input type="text" :disabled="true" v-model="workerName" placeholder="请填写劳动者姓名">
        </view>
      </view>
      <view class="in-text">
        <view class="itext-word">
          性别
        </view>
        <view class="intext-in">
          <radio-group name="" @change="setsex($event)" class="bianxin">
            <label>
              <radio :value="1" :disabled="workerSex==0" :checked="workerSex==1" color="#2f67ff" /><text>男</text>
            </label>
            <label>
              <radio :value="0" :disabled="workerSex==1" :checked="workerSex==0" color="#2f67ff" /><text>女</text>
            </label>
          </radio-group>
        </view>
      </view>
      <view class="in-text">
        <view class="itext-word">
          身份证号码
        </view>
        <view class="intext-in">
          <input type="text" :disabled="true" v-model="workerIdentityCard" placeholder="请填写劳动者身份证号码">
        </view>
      </view>
    </view>
    <view class="title">劳动合同的类别，期限，试用期</view>
    <view class="contract-info-box">
      <view class="in-text">
        <view class="itext-word">
          选择合同开始时间
        </view><!-- contractWorkAddress -->
        <!-- "请选择包工头" -->
        <view class="intext-in">
          <picker mode="date" @change="setcontractWorkStart($event)">
            <view style="color: #808080;">{{contractWorkStart}}</view>
          </picker>
        </view>
      </view>
    </view>
    <view class="title">工资和支付方式</view>
    <view class="contract-info-box">
      <view class="in-text">
        <view class="itext-word">
          选择支付工资基本方式
        </view>
      </view>
      <view class="xuanxangka" style="justify-content: space-around;">
        <view :class="contractSalaryType==0?'world-color card':'card'">
			<view class="icon">1</view>
			<view @click="setcontractSalaryType(0)" >月基本工资</view></view>
        <view :class="contractSalaryType==1?'world-color card':'card'">
          <view class="icon">2</view>
          <view @click="setcontractSalaryType(1)">日基本工资</view>
        </view>
        <!-- <view :class="contractSalaryType==2?'world-color card':'card'">
          <view class="icon">3</view>
          <view @click="setcontractSalaryType(2)">计件</view>
        </view> -->
      </view>
      <view class="jiabantype-box" v-if="contractSalaryType==0">
						<view class="text-input-box-it">
							<input type="text" @blur="isNum(contractSalaryMonthBase)" v-model="contractSalaryMonthBase" placeholder="请输入月基本工资">
						</view>
						<view class="text-box-jiaban">
							<view class="bgcolor-box">
								<input v-if="" type="text" @blur="isNum(contractSalaryMonthAdd)" v-model="contractSalaryMonthAdd" placeholder="请输入加班工资">
							</view>
							<text>每小时</text>
						</view>
      </view>
      <view class="jiabantype-box" v-if="contractSalaryType==1">
        <view class="text-input-box-it">
          <input type="text" @blur="isNum(contractSalaryDayBase)" v-model="contractSalaryDayBase"
            placeholder="请输入日基本工资">
        </view>
        <view class="text-box-jiaban">
          <view class="bgcolor-box">
            <input type="text" @blur="isNum(contractSalaryDayAdd)" v-model="contractSalaryDayAdd" placeholder="请输入加班工资">
          </view>
          <text>每小时</text>
        </view>
      </view>
      <!-- <view class="xuanxangbox" v-if="contractSalaryType==2">
        <view class="xuanxang">
          <picker class="picker-cs-box" mode="selector" :range="Workertypelist" @change="setworkertypeval($event)">
            <view class="sanjiaoxing-box">
              <view style="color: #808080;">{{workertypeval}}</view>
              <image src="../../../static/images/sanjiaoxing.png"></image>
            </view> 
          </picker>
        </view>
        <view class="xuanxang" v-if="contractSalaryType==2">
          <input type="text" @blur="isNum(contractSalaryNumberBase)" v-model="contractSalaryNumberBase"
            placeholder="请输入金额" style="text-align: center; font-size: 30rpx; color: black;">
        </view>
        <view class="xuanxang" v-show="contractSalaryType==2">
          <picker class="picker-cs-box" mode="selector" :range="jijianlist" @change="setjijianlistval($event)">
            <view class="sanjiaoxing-box" style="justify-content: center;">
              <view style="color: #808080;">{{jijianlistval}}</view>
              <image src="../../../static/images/sanjiaoxing.png"></image>
            </view>
          </picker>
        </view>
      </view> -->
      <view class="contract-info-box" v-if="contractSalaryType==2">
        <!-- <view class="in-text">
          <view class="itext-word">
            未完成先发月工资金额
          </view>
          <view class="intext-in">
            <input type="text" v-model="contractSalaryNumberMonth" placeholder="工资金额">
          </view>
        </view> -->
      </view>
      <view style="width: 100%; height: 15rpx;"></view>
    </view>
    <view class="title">工作岗位，工作地点</view>
    <view class="contract-info-box">
      <view class="in-text">
        <view class="itext-word">
          工作岗位
        </view>
        <view class="intext-in">
          <picker mode="selector" :range="workerType" @change="setworkeType($event)">
            <view style="color: #808080;">{{contractWorkType}}</view>
          </picker>
        </view>
      </view>
      <view class="in-text">
        <view class="itext-word">
          工作地点
        </view><!-- contractWorkAddress -->
        <!-- "请选择工作地点" -->
        <view class="intext-in">
          <input type="text" v-model="contractWorkAddress" placeholder="请输入工作地点">
        </view>
      </view>
      <!-- <view class="in-text">
						<view class="itext-word">
							班组
						</view><!-- contractWorkAddress -->
      <!-- "请选择班组" -->
      <!-- <view class="intext-in">
							<picker mode="selector"  :range="workerType" @change="setwokerGroup($event)">
								<view style="color: #808080;">{{workGroup}}</view>
							</picker>
						</view>
					</view> -->
      <view class="in-text">
        <view class="itext-word">
          班组
        </view><!-- contractWorkAddress -->
        <!-- "请选择包工头" -->
        <view class="intext-in">
          <picker mode="selector" :disabled="disClick" :range="contractorForemans"
            @change="setcontractorForeman($event)">
            <view style="color: #808080;">{{contractorForeman}}</view>
          </picker>
        </view>
      </view>
    </view>
    <view class="made-contract">
      <button @click="madecontract()">生成合同</button>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        contractorForemans: ['请先选择上方用人单位'],
        contractorForeman: '请选择班组',
        isheader: '',
        unitid: '',
        unitIds: [],
        contractProjectName: '请选择项目',
        workGroup: '请选择班组',
        workerType: [],
        contractOrder: false,
        contractPersonyiimg: [],
        workeAdderss: [],
        daymoney: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18',
          '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'
        ],
        userId: null, //劳动者id 
        contractPersonjiaimg: [],
        unitcontractid: [],
        workerinfo: [],
        subconnect: [],
        subadress: [],
        subphone: [],
        subunitcode: [],
        subunitusername: [],
        subcontractingName: [],
        workertypeval: '请选择类型',
        Workertypeindex: 0,
        Workertypelist: [],
        projectName: '',
        projectId: '',
        workmoney: ['3000', '4000', '5000'],
        jijianlistval: '单位',
        jijianindex: 0,
        jijianlist: [],
        jysum: 0,
        jyindex: 0,
        jycount: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
        countindex: 0,
        count: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
        cindex: 0,
        contractId: '',
        contractNumber: "请选择份数",
        contractOtherRemark: "",
        contractOwnNumber: "请选择份数",
        contractPersonOneImgOne: "",
        contractPersonOneImgTwo: "",
        contractPersonOneTime: new Date().toISOString().slice(0, 10).toString(),
        contractPersonTwoImgOne: "",
        contractPersonTwoTime: "",
        contractRelativeProjectId: 0,
        contractSalaryDayAdd: "",
        contractSalaryDayBase: "",
        contractSalaryMonthAdd: "",
        contractSalaryMonthBase: "",
        contractSalaryNumberBase: "",
        contractSalaryType: 0,
        contractStatus: 0,
        contractTryTime: "",
        contractWorkAddress: "",
        contractWorkContent: "",
        contractWorkEnd: "请选择时间",
        contractWorkStandard: "",
        contractWorkStart: "请选择时间",
        contractWorkTimeType: 0,
        contractWorkTryEnd: "",
        contractWorkTryStart: "",
        contractWorkType: "请选择岗位",
        id: 0,
        isEffective: 0,
        unitAddress: "",
        unitContactAddress: "",
        unitCreditCode: "",
        unitName: "点击选择单位名称",
        unitOwnPerson: "",
        unitOwnPhone: "",
        workerContactAddress: "",
        workerIdentityCard: "",
        workerKindredAddress: "",
        workerKindredName: "",
        workerKindredPhone: "",
        workerKindredRelative: "",
        workerName: "",
        workerPhone: "",
        workerSex: 0,
        contractinfo: {},
        contractSalaryGetTime: '请选择日期',
        contractOtherThing: '',
        workerTryBase: '',
        addressIsNull: false, //项目账号登入没有地址
        contractSalaryNumberMonth: '',
        type: '',
        contractType: '', //合同类型简单超时或者复杂
        relativeProjectId: '',
        relativeUnitId: '',
        workeAdderssid: [],
        personIdentity: 10,
        disClick: false

      }
    },
    onLoad(options) {
      this.projectName = uni.getStorageSync('projectName')
      this.projectId = uni.getStorageSync('projectId')
      this.contractId = this.uuid(8) //方法生成合同编号
      this.getsubcontracting() // 获取用人单位信息
      this.userId = options.id //获取签约合同人的id
      this.type = parseInt(options.type) //type用于判断发起合同为劳工协议或农民工合同
      this.isheader = parseInt(options.isheader)
      this.getworkerinfo(parseInt(options.id)) // 获取劳动者信息
      this.getdanweiheleixing() // 获取工作岗位和工作量单位
      this.getworkeAdderss() //获取项目信息
      this.setcontractWorkTimeType(0)
      if (this.type == 1) { //用于判断发起合同为劳工协议或农民工合同
        this.contractType = 2
      } else {
        this.contractType = 3
      }

    },
    methods: {
      setcontractorForeman(e) { //修改获取包工头字段
        if (this.unitid == '') { //拿不到单位id先选择用人单位
          uni.showToast({
            title: '请先选择用人单位',
            icon: 'none'
          })
          return
        }
        this.contractorForeman = this.contractorForemans[e.detail.value]

      },
      selectbaogontou() { //该方法查询包工头
        if (uni.getStorageSync('usertype') == 3) { //角色身份判断3为包工头
          this.contractorForeman = uni.getStorageSync('nickName') //包工头名字为账户本人
          this.disClick = true
        } else if (uni.getStorageSync('usertype') == 2 && this.personIdentity == 1) { //角色身份判断2为劳资项目
          uni.$get(this.path + '/person/getContractorList/' + this.unitid).then(res => { //查询包工头接口参数为单位id
            console.log('查询包工头', res);
            if (res.code == 200) {
              if (res.data.length == 0) {
                uni.showModal({
                  title: '提示',
                  content: '该劳工未与班组长签约，请联系其班组长进行签约',
                  success: (res) => {
                    if (res.confirm) { //返回选人页面
                      console.log('用户点击了确定');
                      uni.redirectTo({
                        url: '/pages/example/contract/contracter?id=' + 1
                      })
                    } else if (res.cancel) { //返回选人页面
                      uni.redirectTo({
                        url: '/pages/example/contract/contracter?id=' + 1
                      })
                    }

                  },

                })
              }
              this.contractorForemans = []
              for (let i = 0; i < res.data.length; i++) {
                this.contractorForemans.push(res.data[i].personName)
              }
            }
          })
        } else {
          this.contractorForeman = this.workerName
          this.disClick = true
		  
        }
      },
      selectcontractorForeman() { //劳资项目添加关系
        uni.$post(this.path + '/person/addUnitContractorRelative', {
          unitId: this.unitid,
          specialId: this.userId,
          contractorId: uni.getStorageSync('workerId'),
          projectId: this.relativeProjectId
        }).then(res => {
          if (res.code == 200) {
            console.log('查询包工头', res);
            if (res.code == 200) {
              console.log('新增关系成功');
              if (this.type == 1) { //获取劳工协议或农民工合同
                uni.$post(this.path + '/contract/toPicture/3-1', {
                  contractId: this.contractId, //合同编号
                  contractPersonOneImgOne: this.contractPersonOneImgOne, //甲方盖章图片(或者委托人)
                  contractPersonOneImgTwo: this.unitOwnPerson, //甲方法定代表人签印(或者委托人)
                  contractPersonOneTime: this.contractPersonOneTime + ' 00:00:00', //甲方认证时间	
                  contractPersonTwoImgOne: '',
                  contractPersonTwoTime: "",
                  contractRelativeProjectId: this
                  .contractRelativeProjectId, //this.projectId此id需使用uni.getStorageSync('projectId')
                  contractSalaryDayAdd: this.contractSalaryDayAdd, //日加班工资（每小时）
                  contractSalaryDayBase: this.contractSalaryDayBase, //日基本工资
                  contractSalaryMonthAdd: this.contractSalaryMonthAdd, //月加班工资（每小时）
                  contractSalaryMonthBase: this.contractSalaryMonthBase, //月基本工资
                  contractSalaryNumberBase: this.contractSalaryNumberBase, //计件基本工资
                  contractSalaryType: this.contractSalaryType, //薪资类型
                  contractStatus: 2,
                  contractWorkAddress: this.contractWorkAddress,
                  // contractWorkEnd: this.contractWorkEnd,
                  contractWorkStart: this.contractWorkStart + ' 00:00:00',
                  contractWorkTimeType: this.contractWorkTimeType,
                  contractWorkType: this.contractWorkType,
                  isEffective: 0,
                  unitAddress: this.unitAddress,
                  unitContactAddress: this.unitContactAddress,
                  unitCreditCode: this.unitCreditCode,
                  unitName: this.unitName,
                  // unitOwnPerson: this.unitOwnPerson,
                  // unitOwnPhone: this.unitOwnPhone,
                  workerContactAddress: this.workerContactAddress,
                  workerIdentityCard: this.workerIdentityCard,
                  // workerKindredAddress: this.workerKindredAddress,
                  // workerKindredName: this.workerKindredName,
                  // workerKindredPhone: this.workerKindredPhone,
                  // workerKindredRelative: this.workerKindredRelative,
                  workerName: this.workerName,
                  workerPhone: this.workerPhone,
                  workerSex: this.workerSex,
                  workGroup: this.contractorForeman,
                  projectName: this.contractProjectName,
                  relativeProjectId: this.relativeProjectId,
                  relativeUnitId: this.relativeUnitId
                }).then(res => {
                  if (res.code == 200) {
                    console.log('生成图片');
                    if (res.code == 200) {
                      uni.hideLoading()
                      // uni.showToast({
                      // title: '合同生成成功',
                      // icon: 'none',
                      // duration: 1500,
                      // })
                      setTimeout(() => {
                        console.log('成功');
                        this.$emit('contractimg', res.data)
                        this.toccc(res.data)
                      }, 500)
                    }


                  }
                })
                return
              }
              uni.$post(this.path + '/contract/toPicture/2-1', {
                contractId: this.contractId, //合同编号
                contractPersonOneImgOne: this.contractPersonOneImgOne, //甲方盖章图片(或者委托人)
                contractPersonOneImgTwo: this.unitOwnPerson, //甲方法定代表人签印(或者委托人)
                contractPersonOneTime: this.contractPersonOneTime + ' 00:00:00', //甲方认证时间	
                contractPersonTwoImgOne: '',
                contractPersonTwoTime: "",
                contractRelativeProjectId: this
                .contractRelativeProjectId, //this.projectId此id需使用uni.getStorageSync('projectId')
                contractSalaryDayAdd: this.contractSalaryDayAdd, //日加班工资（每小时）
                contractSalaryDayBase: this.contractSalaryDayBase, //日基本工资
                contractSalaryMonthAdd: this.contractSalaryMonthAdd, //月加班工资（每小时）
                contractSalaryMonthBase: this.contractSalaryMonthBase, //月基本工资
                contractSalaryNumberBase: this.contractSalaryNumberBase, //计件基本工资
                contractSalaryType: this.contractSalaryType,
                contractStatus: 2,
                contractWorkAddress: this.contractWorkAddress,
                // contractWorkEnd: this.contractWorkEnd,
                contractWorkStart: this.contractWorkStart + ' 00:00:00',
                contractWorkTimeType: this.contractWorkTimeType,
                contractWorkType: this.contractWorkType,
                isEffective: 0,
                unitAddress: this.unitAddress,
                unitContactAddress: this.unitContactAddress,
                unitCreditCode: this.unitCreditCode,
                unitName: this.unitName,
                // unitOwnPerson: this.unitOwnPerson,
                // unitOwnPhone: this.unitOwnPhone,
                workerContactAddress: this.workerContactAddress,
                workerIdentityCard: this.workerIdentityCard,
                // workerKindredAddress: this.workerKindredAddress,
                // workerKindredName: this.workerKindredName,
                // workerKindredPhone: this.workerKindredPhone,
                // workerKindredRelative: this.workerKindredRelative,
                workerName: this.workerName,
                workerPhone: this.workerPhone,
                workerSex: this.workerSex,
                workGroup: this.contractorForeman,
                projectName: this.contractProjectName,
                relativeProjectId: this.relativeProjectId,
                relativeUnitId: this.relativeUnitId
              }).then(res => {
                if (res.code == 200) {
                  console.log('生成图片');
                  if (res.code == 200) {
                    uni.hideLoading()
                    // uni.showToast({
                    // title: '合同生成成功',
                    // icon: 'none',
                    // duration: 1500,
                    // })
                    setTimeout(() => {
                      console.log('成功');
                      this.$emit('contractimg', res.data)
                      this.toccc(res.data)
                    }, 500)
                  }


                }
              })
            } else {
              uni.hideLoading()
              uni.showToast({
                title: '新增关系失败',
                icon: 'none',

              })
              setTimeout(() => {
                uni.redirectTo({
                  url: './contracter'
                })
              }, 1000)
            }
          }
        })
      },

      isNum(num) { //数字校验
        if (this.isNumber(num)) {
          return num = ''
        } else {
          uni.showToast({
            title: '请输入数字',
            icon: 'none',
            duration: 1500
          })
        }
      },
      validateName(name) {
        // 中文名正则表达式，限制长度为2-4个字符
        const chineseNameRegex = /^[\u4e00-\u9fa5a-zA-Z\s]{2,4}$/;
        // 英文名正则表达式，限制长度为2-10个字符
        const englishNameRegex = /^[a-zA-Z\s]{2,10}$/;
        return chineseNameRegex.test(name) || englishNameRegex.test(name);
      },
      checkName(name) { //姓名字段校验
        // 正则表达式规则：2-4个汉字或字母
        const reg = /^[\u4e00-\u9fa5a-zA-Z]{2,4}$/;
        return reg.test(name);
      },
      isSpecialChar(input) { //效验特殊字符
        const specialCharRegex = /[!@#$%^&*(),.?":{}|<>]/;
        return specialCharRegex.test(input);
      },
      isBlank(str) { //判断是否为空字符串
        return str.trim().length === 0;
      },
      isNumber(input) { //数字校验
        const numberRegex = /^[0-9]+$/;
        return numberRegex.test(input);
      },
      uuid(len, radix) { //uuid生成
        var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
        var uuid = [],
          i;
        radix = radix || chars.length;

        if (len) {
          // Compact form
          for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
        } else {
          // rfc4122, version 4 form
          var r;

          // rfc4122 requires these characters
          uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
          uuid[14] = '4';

          // Fill in random data.  At i==19 set the high bits of clock sequence as
          // per rfc4122, sec. 4.1.5
          for (i = 0; i < 36; i++) {
            if (!uuid[i]) {
              r = 0 | Math.random() * 16;
              uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
            }
          }
        }

        return uuid.join('');
      },
      getworkeAdderss() { //获取项目
        uni.$post(this.path + '/project/queryAll', {
          id: '0',
          orderBy: "",
          pageNo: 0,
          pageSize: 0,
          projectCreateUnit: "",
          projectName: "",
          returnFields: ""
        }).then(res => {
          console.log('获取项目结果', res);
          if (res.code == 200) {
            for (let i = 0; i < res.data.records.length; i++) {
              this.workeAdderss.push(res.data.records[i].projectName)
              this.workeAdderssid.push(res.data.records[i].id)
            }
            console.log('workeAdderss', this.workeAdderss);
            if (this.workeAdderss.length == 0) {
              uni.showToast({
                title: '获取项目信息异常,返回首页中......',
                icon: 'none',
                duration: 1500
              })
              setTimeout(() => {
                uni.switchTab({
                  url: '../home/index'
                })
              }, 1500)
            }
          } else {
            uni.showToast({
              title: '项目信息获取失败,返回首页中......',
              icon: 'none',
              duration: 1000
            })
            setTimeout(() => {
              uni.switchTab({
                url: '../home/index'
              })
            }, 1000)
          }

        })
      },
      getdanweiheleixing() { //获取字典内含单位，岗位，计件岗位
        uni.$get(this.path + 'system/dict/data/type/' + uni.getStorageSync('leixing')).then(res => {
          if (res.code == 200) {
            for (let i = 0; i < res.data.length; i++) {
              this.Workertypelist.push(res.data[i].dictLabel)
            }
          } else {
            uni.showToast({
              title: '工作岗位信息获取失败,返回首页中......',
              icon: 'none',
              duration: 1000
            })
            setTimeout(() => {
              uni.switchTab({
                url: '../home/index'
              })
            }, 1000)
          }
        })
        uni.$get(this.path + 'system/dict/data/type/' + uni.getStorageSync('danwei')).then(res => {
          if (res.code == 200) {
            for (let i = 0; i < res.data.length; i++) {
              this.jijianlist.push(res.data[i].dictLabel)
            }
          } else {
            uni.showToast({
              title: '单位类型获取失败,返回首页中......',
              icon: 'none',
              duration: 1000
            })
            setTimeout(() => {
              uni.switchTab({
                url: '../home/index'
              })
            }, 1000)
          }
        })
        uni.$get(this.path + 'system/dict/data/type/' + uni.getStorageSync('gangwei')).then(res => {
          if (res.code == 200) {
            console.log('gangwei', res);
            for (let i = 0; i < res.data.length; i++) {
              this.workerType.push(res.data[i].dictLabel)
            }
          } else {
            uni.showToast({
              title: '单位类型获取失败,返回首页中......',
              icon: 'none',
              duration: 1000
            })
            setTimeout(() => {
              uni.switchTab({
                url: '../home/index'
              })
            }, 1000)
          }
        })
      },
      // 获取劳动者信息
      getworkerinfo(id) {
        console.log('获取劳动者信息')
        uni.$get(this.path + '/person/get/' + id).then(res => {
          console.log('获取劳动者信息 result', res);
          if (res.code == 200) {
            this.workerName = res.data.personName
            this.workerSex = res.data.personSex
            this.workerIdentityCard = res.data.personIdentityCard
            this.workerPhone = res.data.personPhone
            this.workerContactAddress = res.data.personAddress //——————————————————————地址绑定？————————————————————
            this.addressIsNull = (res.data.personAddress == null ? false : true) // 没有地址进来就允许输入
            this.personIdentity = res.data.personIdentity
          } else {
            uni.showToast({
              title: '获取不了劳动者信息，请重试',
              icon: 'none',
              duration: 1500
            })
            setTimeout(() => {
              uni.redirectTo({
                url: './contracter'
              })
            }, 1500)
          }
        })
      },
      setworkeAdderss(e) { //获取项目名称项目id
        this.contractProjectName = this.workeAdderss[e.detail.value]
        this.relativeProjectId = this.workeAdderssid[e.detail.value]
        this.contractOrder = true //该参数用于判断选择用人单位前是否选择项目
      },
      setsubcontracting(e) { //选择用人单位
        if (this.contractOrder == false) {
          uni.showToast({
            title: '请先选择上方的项目',
            icon: 'none',
            duration: 1000
          })
          setTimeout(() => {}, 1000)
          return
        }

        this.unitid = this.unitIds[e.detail.value]
        this.contractPersonOneImgOne = this.contractPersonjiaimg[e.detail.value]
        this.unitName = this.subcontractingName[e.detail.value]
        this.unitCreditCode = this.subunitcode[e.detail.value]
        this.unitOwnPerson = this.subunitusername[e.detail.value]
        this.unitOwnPhone = this.subphone[e.detail.value]
        this.unitAddress = this.subadress[e.detail.value]
        this.unitContactAddress = this.subconnect[e.detail.value]
        this.contractRelativeProjectId = this.unitcontractid[e.detail.value]
        this.relativeUnitId = this.unitcontractid[e.detail.value]
        this.selectbaogontou() //查询包工头
      },
      getsubcontracting() { //查询用人单位
        uni.$post(this.path + '/unit/queryAll', {
          pageNo: 1,
          pageSize: 100000,
          unitFlag: 0
        }).then(res => {
          console.log('获取用人单位信息', res);
          if (res.code == 200) {
            for (let i = 0; i < res.data.records.length; i++) {
              this.contractPersonjiaimg.push(res.data.records[i].unitPromiseImgTwo)
              this.unitcontractid.push(parseInt(res.data.records[i].id))
              this.subcontractingName.push(res.data.records[i].unitName)
              this.subunitusername.push(res.data.records[i].unitOwnName)
              this.subunitcode.push(res.data.records[i].unitCreditCode)
              this.subphone.push(res.data.records[i].unitOwnPhone)
              this.subadress.push(res.data.records[i].unitWhere) //——————————————————————地址绑定？————————————————————
              this.subconnect.push(res.data.records[i].unitWorkWhere)
              this.unitIds.push(res.data.records[i].id)
            }
            // console.log('单位名称',this.subcontractingName);
            // console.log('社会信用代码',this.subunitcode);
            // console.log('负责人名',this.subunitusername);
            // console.log('电话',this.subphone);
            // console.log('住所',this.subadress);
            // console.log('联系地址',this.subconnect);
            // console.log('项目id',this.unitcontractid);
            console.log('盖章图片', this.contractPersonjiaimg);
          } else {
            uni.showToast({
              title: '获取不了用人单位信息，请先添加单位，或重试',
              icon: 'none',
              duration: 1500
            })
            setTimeout(() => {
              uni.redirectTo({
                url: './contracter'
              })
            }, 1500)
          }
        })
      },
      setwokerGroup(e) { //选择班组
        this.workGroup = this.workerType[e.detail.value]
      },
      setworkeType(e) { //选择工作岗位
        this.contractWorkType = this.workerType[e.detail.value]
      },
      setsex(e) { //选择性别
        this.workerSex = e.detail.value;
        console.log(this.workerSex);

      },
      setworkertypeval(e) { //选择计件类型工作岗位
        this.workertypeval = this.Workertypelist[e.detail.value]

      },

      setjijianlistval(e) { //选择单位如米，平方米
        this.jijianlistval = this.jijianlist[e.detail.value]
      },
      setcontractSalaryType(num) { //选择工资发放类型
        this.contractSalaryType = num
      },
      setcontractWorkStart(e) { //选择合同开始时间
        this.contractWorkStart = e.detail.value
        this.contractWorkStart = this.contractWorkStart.toString()
        console.log(this.contractWorkStart);

      },
      setcontractWorkTimeType(num) { //该方法选择合同时间，并把其它不选择时间设为空串
        this.contractWorkTimeType = num
        if (num == 2) { //固定期限日期
          this.contractWorkTryStart = ''
          this.contractWorkTryEnd = ''
          this.contractWorkEnd = '请选择时间'
          this.contractWorkStart = new Date().toISOString().slice(0, 10).toString()
          console.log('固定期限日期', this.contractWorkStart);
        } else if (num == 0) {
          this.contractWorkTryEnd = '请选择时间'
          this.contractWorkTryStart = '请选择时间'
        } else {
          this.contractWorkTryStart = ''
          this.contractWorkTryEnd = ''
        }
      },
      tomade(id) { //合同模板跳转
        uni.navigateTo({
          url: './contractmodel?id=' + id
        })
      },
      toccc(id) { //生成合同并跳转
        uni.redirectTo({
          url: './contracted/contracted?id=' + id
        })
      },
      madecontract() { //该方法上传合同信息并生成合同图片预览
        console.log('--------点击了生成');
        if (this.contractWorkStart == '请选择时间' && this.contractWorkTimeType == 0) {
          uni.showToast({
            title: '请选择时间',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.contractWorkType.length == 0 && this.contractWorkType == '请选择岗位') {
          uni.showToast({
            title: '请选择工作岗位',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.contractWorkAddress.length == 0) {
          uni.showToast({
            title: '请填写工作地点',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.contractSalaryMonthBase.length == 0 && this.contractSalaryType == 0) {
          uni.showToast({
            title: '请填写月基本工资',
            icon: 'none',
            duration: 1500
          })
          return
        }
        else if(this.contractSalaryMonthAdd.length==0&&this.contractSalaryType==0){
        	uni.showToast({
        		title:'填写月加班工资',
        		icon:'none',
        		duration:1500
        	})
        	return
        }
        else if (this.contractSalaryDayBase.length == 0 && this.contractSalaryType == 1) {
          uni.showToast({
            title: '填写日基本工资',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.contractSalaryDayAdd.length == 0 && this.contractSalaryType == 1) {
          uni.showToast({
            title: '填写日加班工资',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.contractSalaryNumberBase.length == 0 && this.contractSalaryType == 2) {
          uni.showToast({
            title: '填输入金额',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.unitName == '点击选择单位名称') {
          uni.showToast({
            title: '填选择单位名称',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.contractWorkAddress == '请选择工作地点') {
          uni.showToast({
            title: '请选择工作地点',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.contractProjectName == '请选择项目') {
          uni.showToast({
            title: '请选择项目',
            icon: 'none',
            duration: 1500
          })
          return
        } else if (this.contractorForeman == '请选择班组') {
          uni.showToast({
            title: '请选择班组',
            icon: 'none',
            duration: 1500
          })
          return
        }

        uni.showLoading({
          title: '合同生成中',
        })
        uni.$put(this.path + '/contract/add', { //上传添加合同信息
          contractId: this.contractId, //合同编号
          contractPersonOneImgOne: this.contractPersonOneImgOne, //甲方盖章图片(或者委托人)
          contractPersonOneImgTwo: this.unitOwnPerson, //甲方法定代表人签印(或者委托人)
          contractPersonOneTime: this.contractPersonOneTime + ' 00:00:00', //甲方认证时间	
          contractPersonTwoImgOne: '',
          contractPersonTwoTime: "",
          contractRelativeProjectId: this
          .contractRelativeProjectId, //this.projectId此id需使用uni.getStorageSync('projectId')
          contractSalaryDayAdd: this.contractSalaryDayAdd, //日加班工资（每小时）
          contractSalaryDayBase: this.contractSalaryDayBase, //日基本工资
          contractSalaryMonthAdd: this.contractSalaryMonthAdd, //月加班工资（每小时）
          contractSalaryMonthBase: this.contractSalaryMonthBase, //月基本工资
          contractSalaryNumberBase: this.contractSalaryNumberBase, //计件基本工资
          contractSalaryType: this.contractSalaryType,
          contractStatus: 2,
          contractWorkAddress: this.contractWorkAddress,
          // contractWorkEnd: this.contractWorkEnd,
          contractWorkStart: this.contractWorkStart + ' 00:00:00',
          contractWorkTimeType: this.contractWorkTimeType,
          contractWorkType: this.contractWorkType,
          isEffective: 0,
          unitAddress: this.unitAddress,
          unitContactAddress: this.unitContactAddress,
          unitCreditCode: this.unitCreditCode,
          unitName: this.unitName,
          // unitOwnPerson: this.unitOwnPerson,
          // unitOwnPhone: this.unitOwnPhone,
          workerContactAddress: this.workerContactAddress,
          workerIdentityCard: this.workerIdentityCard,
          // workerKindredAddress: this.workerKindredAddress,
          // workerKindredName: this.workerKindredName,
          // workerKindredPhone: this.workerKindredPhone,
          // workerKindredRelative: this.workerKindredRelative,
          workerName: this.workerName,
          workerPhone: this.workerPhone,
          workerSex: this.workerSex,
          contractType: this.contractType,
          workGroup: this.contractorForeman,
          projectName: this.contractProjectName,
          relativeProjectId: this.relativeProjectId,
          relativeUnitId: this.relativeUnitId
        }).then(res => {
          if (res.code == 200) {
            console.log('新增合同成功');
            // 登录用户身份 5劳资专员-个人 4劳工 3包工头 2劳资专员-项目 1管理员
            console.log('usertype', uni.getStorageSync('usertype'));
            if (uni.getStorageSync('usertype') == 2) {
              this.selectcontractorForeman() //添加劳资与包工头或劳工关系
              return
            }
            uni.$post(this.path + '/person/addUnitWorkerRelative', { //添加劳工与包工头关系
              unitId: this.unitid,
              workerId: this.userId,
              contractorId: uni.getStorageSync('workerId'),
              projectId: this.relativeProjectId
            }).then(res => {
              if (res.code == 200) {
                console.log('新增关系成功');
                if (this.type == 1) {
                  uni.$post(this.path + '/contract/toPicture/3-1', {
                    /**
                     * 1-0：复杂空白合同
                     * 1-1：复杂填充合同
                     * 2-0：农民工空白合同
                     * 2-1：农民工填充合同
                     * 3-0：简易用工空白合同
                     * 3-1：简易用工填充合同
                     */
                    contractId: this.contractId, //合同编号
                    contractPersonOneImgOne: this.contractPersonOneImgOne, //甲方盖章图片(或者委托人)
                    contractPersonOneImgTwo: this.unitOwnPerson, //甲方法定代表人签印(或者委托人)
                    contractPersonOneTime: this.contractPersonOneTime + ' 00:00:00', //甲方认证时间	
                    contractPersonTwoImgOne: '',
                    contractPersonTwoTime: "",
                    contractRelativeProjectId: this
                    .contractRelativeProjectId, //this.projectId此id需使用uni.getStorageSync('projectId')
                    contractSalaryDayAdd: this.contractSalaryDayAdd, //日加班工资（每小时）
                    contractSalaryDayBase: this.contractSalaryDayBase, //日基本工资
                    contractSalaryMonthAdd: this.contractSalaryMonthAdd, //月加班工资（每小时）
                    contractSalaryMonthBase: this.contractSalaryMonthBase, //月基本工资
                    contractSalaryNumberBase: this.contractSalaryNumberBase, //计件基本工资
                    contractSalaryType: this.contractSalaryType,
                    contractStatus: 2,
                    contractWorkAddress: this.contractWorkAddress,
                    // contractWorkEnd: this.contractWorkEnd,
                    contractWorkStart: this.contractWorkStart + ' 00:00:00',
                    contractWorkTimeType: this.contractWorkTimeType,
                    contractWorkType: this.contractWorkType,
                    isEffective: 0,
                    unitAddress: this.unitAddress,
                    unitContactAddress: this.unitContactAddress,
                    unitCreditCode: this.unitCreditCode,
                    unitName: this.unitName,
                    // unitOwnPerson: this.unitOwnPerson,
                    // unitOwnPhone: this.unitOwnPhone,
                    workerContactAddress: this.workerContactAddress,
                    workerIdentityCard: this.workerIdentityCard,
                    // workerKindredAddress: this.workerKindredAddress,
                    // workerKindredName: this.workerKindredName,
                    // workerKindredPhone: this.workerKindredPhone,
                    // workerKindredRelative: this.workerKindredRelative,
                    workerName: this.workerName,
                    workerPhone: this.workerPhone,
                    workerSex: this.workerSex,
                    workGroup: this.workGroup,
                    projectName: this.contractProjectName,
                    relativeProjectId: this.relativeProjectId,
                    relativeUnitId: this.relativeUnitId
                  }).then(res => {
                    if (res.code == 200) {
                      console.log('生成图片');
                      if (res.code == 200) {
                        uni.hideLoading()
                        // uni.showToast({
                        // title: '合同生成成功',
                        // icon: 'none',
                        // duration: 1500,
                        // })
                        setTimeout(() => {
                          console.log('成功');
                          this.$emit('contractimg', res.data)
                          this.toccc(res.data)
                        }, 500)
                      }


                    }
                  })
                  return
                }
                uni.$post(this.path + '/contract/toPicture/2-1', {
                  contractId: this.contractId, //合同编号
                  contractPersonOneImgOne: this.contractPersonOneImgOne, //甲方盖章图片(或者委托人)
                  contractPersonOneImgTwo: this.unitOwnPerson, //甲方法定代表人签印(或者委托人)
                  contractPersonOneTime: this.contractPersonOneTime + ' 00:00:00', //甲方认证时间	
                  contractPersonTwoImgOne: '',
                  contractPersonTwoTime: "",
                  contractRelativeProjectId: this
                  .contractRelativeProjectId, //this.projectId此id需使用uni.getStorageSync('projectId')
                  contractSalaryDayAdd: this.contractSalaryDayAdd, //日加班工资（每小时）
                  contractSalaryDayBase: this.contractSalaryDayBase, //日基本工资
                  contractSalaryMonthAdd: this.contractSalaryMonthAdd, //月加班工资（每小时）
                  contractSalaryMonthBase: this.contractSalaryMonthBase, //月基本工资
                  contractSalaryNumberBase: this.contractSalaryNumberBase, //计件基本工资
                  contractSalaryType: this.contractSalaryType,
                  contractStatus: 2,
                  contractWorkAddress: this.contractWorkAddress,
                  // contractWorkEnd: this.contractWorkEnd,
                  contractWorkStart: this.contractWorkStart + ' 00:00:00',
                  contractWorkTimeType: this.contractWorkTimeType,
                  contractWorkType: this.contractWorkType,
                  isEffective: 0,
                  unitAddress: this.unitAddress,
                  unitContactAddress: this.unitContactAddress,
                  unitCreditCode: this.unitCreditCode,
                  unitName: this.unitName,
                  // unitOwnPerson: this.unitOwnPerson,
                  // unitOwnPhone: this.unitOwnPhone,
                  workerContactAddress: this.workerContactAddress,
                  workerIdentityCard: this.workerIdentityCard,
                  // workerKindredAddress: this.workerKindredAddress,
                  // workerKindredName: this.workerKindredName,
                  // workerKindredPhone: this.workerKindredPhone,
                  // workerKindredRelative: this.workerKindredRelative,
                  workerName: this.workerName,
                  workerPhone: this.workerPhone,
                  workerSex: this.workerSex,
                  workGroup: this.workGroup,
                  projectName: this.contractProjectName,
                  relativeProjectId: this.relativeProjectId,
                  relativeUnitId: this.relativeUnitId
                }).then(res => {
                  if (res.code == 200) {
                    console.log('生成图片');
                    if (res.code == 200) {
                      uni.hideLoading()
                      // uni.showToast({
                      // title: '合同生成成功',
                      // icon: 'none',
                      // duration: 1500,
                      // })
                      setTimeout(() => {
                        console.log('成功');
                        this.$emit('contractimg', res.data)
                        this.toccc(res.data)
                      }, 500)
                    }


                  }
                })
              } else {
                uni.hideLoading()
                uni.showToast({
                  title: '新增关系失败',
                  icon: 'none',

                })
                setTimeout(() => {
                  uni.redirectTo({
                    url: './contracter'
                  })
                }, 1000)
              }
            })
          } else { //失败返回选人
            console.log('生成合同的code不为200', res);
            uni.hideLoading()
            uni.showToast({
              title: '合同生成失败' + res.message,
              icon: 'none',
              duration: 1500,
            })
            setTimeout(() => {
              uni.redirectTo({
                url: './contracter'
              })
            }, 1500)
            return
            // setTimeout(() => {
            //   uni.navigateBack()
            // }, 1000)
          }
        })

      }
    }
  }
</script>

<style lang="scss" scoped>
  .picker-cs-box {
    width: 100%;
    display: flex;
    justify-content: right;
    align-items: center;
    font-size: 28rpx;

    .sanjiaoxing-box {
      width: 100%;
      padding-right: 10rpx;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: space-between;

      view {
        width: fit-content;
        min-width: 150rpx;
      }

      image {
        width: 25rpx;
        height: 25rpx;
        // transform: rotate(180deg);
      }
    }
  }

  .made-contract {
    margin-top: 40rpx;
    width: 100%;
    height: 200rpx;
    display: flex;
    justify-content: center;
    align-items: center;

    button {
      width: 80%;
      height: 35px;
      line-height: 35px;
      color: white;
      font-size: 14px;
      background-color: #2f67ff;
    }
  }

  .contract-number {
    width: 90%;
    margin: 0 auto;
    height: 30px;
    font-size: 12px;
    color: #bfbfbf;
    line-height: 30px;
  }

  .title {
    width: 95%;
    margin: 0 auto;
    margin-top: 5px;
    height: 20px;
    line-height: 20px;
    font-size: 15px;
    border-left: 4px solid #2f67ff;
    padding-left: 0.855%;
    box-sizing: border-box;
  }

  .contract-info-box {
    border-radius: 8px;
    background-color: white;
    margin: 0 auto;
    margin-top: 10px;
    width: 95%;

    .xuanxangka {
      width: 90%;
      margin: 0 auto;
      height: 25px;
      display: flex;
      align-items: center;

      .card {
        width: 35%;
        height: 100%;
        text-align: center;
        line-height: 25px;
        font-size: 14px;
        display: flex;
        justify-content: center;
        align-items: center;

        .icon {
          width: 15px;
          height: 15px;
          line-height: 15px;
          text-align: center;
          border-radius: 50%;
          border: 1px solid #bfbfbf;
          color: #bfbfbf;
          font-size: 10;
        }
      }
    }

    .picker-box {
      width: 95%;
      // min-height: 120px;
      height: fit-content;
      background-color: #f6f6f6;
      margin: 0 auto;
      margin-top: 10px;
      margin-bottom: 10px;
      padding-top: 10px;

      .picker-list {
        width: 95%;
        margin: 0 auto;
        display: flex;
        justify-content: space-around;
        align-items: center;
        font-size: 14px;

        .picker-x {
          padding: 5px;
          width: 35%;
          height: 25px;
          background-color: white;
          display: flex;
          justify-content: space-between;
          align-items: center;

          picker {
            width: 100%;
            display: flex;
            align-items: center;

            .sanjiaoxing-box {
              width: 100%;
              display: flex;
              align-items: center;
              justify-content: space-between;

              image {
                margin-left: 40rpx;
                width: 25rpx;
                height: 25rpx;
                // transform: rotate(180deg);
              }

            }
          }

        }
      }
    }

    .in-text {
      display: flex;
      width: 95%;
      height: 35px;
      margin: 0 auto;
      justify-content: space-between;
      align-items: center;
      font-size: 14px;
      border-bottom: #f6f9fc 1px solid;

      .itext-word {
        width: fit-content;
      }

      .intext-in {
        width: 60%;

        picker {
          float: right;
        }

        .bianxin {
          transform: scale(0.8);
          font-size: 13px;
          float: right;
          width: 200rpx;
          display: flex;
          justify-content: space-between;
        }

        input {
          width: 100%;
          font-size: 13px;
          text-align: right;
        }
      }

    }

    .jiabantype-box {
      width: 95%;
      margin: 0 auto;
      margin-top: 25rpx;
      height: fit-content;
      border-bottom: #f6f9fc 1px solid;

      .text-input-box-it {
        display: flex;
        align-items: center;
        min-height: 80rpx;
        background-color: #f6f6f6;
        height: fit-content;
        width: 90%;
        margin: 0 auto;

        input {
          font-size: 30rpx;
          width: 95%;
        }
      }

      .text-box-jiaban {
        in-height: 80rpx;
        height: fit-content;
        width: 90%;
        margin: 0 auto;
        margin-top: 15rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 80rpx;

        .bgcolor-box {
          display: flex;
          align-items: center;
          height: 80rpx;
          width: calc(100% - 100rpx);
          background-color: #f6f6f6;

          input {
            height: 100%;
            font-size: 30rpx;
            width: 100%;

          }
        }

        text {
          text-align: right;
          width: 100rpx;
          font-size: 30rpx;
          color: #bfbfbf;
        }
      }
    }

    .xuanxangbox {
      width: 95%;
      margin: 0 auto;
      height: 80px;
      display: flex;
      justify-content: space-around;
      align-items: center;
      border-bottom: #f6f9fc 1px solid;

      .xuanxang {
        width: 30%;
        height: 50px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 12px;
        background-color: #f6f6f6;
        color: #bfbfbf;
      }

      .text-input-box {
        display: flex;
        align-items: center;
        min-height: 80rpx;
        background-color: #f6f6f6;
        height: fit-content;
        width: 90%;
        margin: 0 auto;

        input {
          font-size: 30rpx;
          width: 95%;
        }
      }
    }

    .text-box {
      width: 95%;
      margin: 0 auto;
      height: 120px;

      textarea {
        width: 100%;
        height: 100px;
        background: #f6f6f6;
        font-size: 14px;
      }

      .totalnum {
        background: #f6f6f6;
        width: 100%;
        text-align: right;
        font-size: 12px;
        color: #bfbfbf;
      }
    }
  }

  .world-color {
    color: #2f67ff;

    .icon {
      border-color: #2f67ff !important;
      color: #2f67ff !important;
    }
  }
</style>
